﻿function ShowChoiceDiv(strDivID, width, height) {
    //debugger;
    //如果是选择资产编号，先检查是否有选资产类别
    if (strDivID == "divAsset")
        if (!ChoiceAsset())
            return;
    if (strDivID == "divPR")
        ChoicePR();

    
    ShowBackgroundDiv();

    var div = document.getElementById(strDivID);
    div.style.left = (document.body.offsetWidth - width) / 2;
    div.style.top = (document.body.offsetHeight - height) / 2;
    div.style.display = "block";
    div.style.height = height;
    div.style.width = width;
}

function ChoiceAsset() {
    var assetType = document.getElementById("ctl00_Body_ddlAssetType").value;
    if (assetType == "") {
        alert("請先選擇資產類別！");
        return false;
    }
    var txtTable = document.getElementById("ctl00_Body_UCSelectAssetNO1_txtQueryTableName");
    if (assetType == "1")
        txtTable.value = "tbl_master";
    else if (assetType == "2")
        txtTable.value = "tbl_control";
    return true;
}

function ChoicePR() {
    var txtTable = document.getElementById("ctl00_Body_UCSelectPR1_txtTableName");
    txtTable.value = "resda";
}

function ShowBackgroundDiv() {
    var obj = document.getElementById("divBack");
    obj.style.display = "block";
    obj.style.width = document.body.clientWidth;
    obj.style.height = document.body.clientHeight;

    var aryDiv = new Array("ctl00_Body_ddlAssetType", "ctl00_Body_ddlBuyCurrency", "ctl00_Body_ddlCorrectCurrency", "ctl00_Body_ddlCurrentStatus", "ctl00_Body_ddlCorrectType", "ctl00_Body_ddlCorrectStatus");
    for (var i = 0; i < aryDiv.length; i++) {
        var obj = document.getElementById(aryDiv[i]);
        if (obj == null)
            continue;
        obj.style.display = "none";
    }
}

function Unlock() {
    var backObj = document.getElementById("divBack");
    backObj.style.display = "none";

    var aryDiv = new Array("divQuery", "divAsset", "divAttach", "divImages", "divPR");
    for (var i = 0; i < aryDiv.length; i++) {
        var obj = document.getElementById(aryDiv[i]);
        if (obj == null)
            continue;
        obj.style.display = "none";
    }

    var aryDiv = new Array("ctl00_Body_ddlAssetType", "ctl00_Body_ddlBuyCurrency", "ctl00_Body_ddlCorrectCurrency", "ctl00_Body_ddlCurrentStatus", "ctl00_Body_ddlCorrectType", "ctl00_Body_ddlCorrectStatus");
    for (var i = 0; i < aryDiv.length; i++) {
        var obj = document.getElementById(aryDiv[i]);
        if (obj == null)
            continue;
        obj.style.display = "block";
    }
}

function SetAssetSelectedValue(strAssetNO, strKeepDept, strKeeper, strChiName, strBrand, strSpec, strModel, strKeeperNO) {
    Unlock();
    document.getElementById("ctl00_Body_txtAssetNO").value = strAssetNO;
    document.getElementById("ctl00_Body_lblKeepDept").value = strKeepDept;
    document.getElementById("ctl00_Body_lblKeeper").value = strKeeperNO + "/" + strKeeper;
    document.getElementById("ctl00_Body_lblChiName").value = strChiName;
    document.getElementById("ctl00_Body_lblBrand").value = strBrand;
    document.getElementById("ctl00_Body_lblSpec").value = strSpec;
    document.getElementById("ctl00_Body_lblModuleNO").value = strModel;

}

function SetPRValue(strPRNO) {
    Unlock();
    document.getElementById("ctl00_Body_txtPRNO").value = strPRNO;
}

function UploadAttach(strAttachURL, strAttachInfo) {
    //返回多个Attach的信息，多个Attach之间以；间隔，而一个Attach之间以“-”分隔客户端名字和服务器端名字
    Unlock();
    document.getElementById("ctl00_Body_lblCorrectAttach").innerHTML = strAttachURL;
    document.getElementById("ctl00_Body_txtAttachInfo").value = strAttachInfo;
    document.getElementById("ctl00_Body_btnAttach").click();
}

function UploadImage(strImageURL, strImageInfo) {
    Unlock();
    //document.getElementById("ctl00_Body_lblCorrectPictures").innerHTML = strImageURL;
    document.getElementById("ctl00_Body_txtImageInfo").value = strImageInfo;
    document.getElementById("ctl00_Body_btnImage").click();
}

function checkNumber(e) {
    var key = window.event ? e.keyCode : e.which;
    var keychar = String.fromCharCode(key);
    if ((key > 47 && key < 58) || key == 46)
        return true;
    alert("只能輸入數字或者小數點！");
    return false;
}

function ChangeStatus(obj) {
    if (obj.value == "" || obj.value == "1")
        return;
    document.getElementById("ctl00_Body_rblCorrectCycle_3").checked = true;
    document.getElementById("ctl00_Body_ddlCorrectType").value = "3";
    document.getElementById("ctl00_Body_ddlCorrectStatus").value = "3";
}

